package com.glasses.business.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.glasses.business.R;
import com.glasses.business.entity.PayInfo;
import com.glasses.business.event.BussEvent;
import com.glasses.business.pay.com.PayAgent;
import com.glasses.business.pay.com.PayAgentUtils;
import com.glasses.business.pay.com.PayListener;

import org.haitao.common.utils.AppLog;
import org.haitao.common.utils.ToastUtil;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

/**
 * Author：邓勇军
 * English Name：Deng,The Sky Fucker!
 * Email：dandycoder@126.com
 * Date：2017/3/10
 * Version：1.0
 */

public class PayActivity extends Activity {
    @InjectView(R.id.wxSelect)
    ImageView wxSelect;
    @InjectView(R.id.wxRv)
    RelativeLayout wxRv;
    @InjectView(R.id.aliPaySelect)
    ImageView aliPaySelect;
    @InjectView(R.id.aliPayRv)
    RelativeLayout aliPayRv;
    @InjectView(R.id.payMoney)
    TextView payMoney;
    @InjectView(R.id.payTime)
    TextView payTime;
    @InjectView(R.id.payBuy)
    TextView payBuy;
    @InjectView(R.id.ly_back)
    LinearLayout lyBack;
    @InjectView(R.id.title_tv)
    TextView titleTv;
    private PayInfo moneyPay;
    private int payType = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏
        setContentView(R.layout.activity_pay);
        ButterKnife.inject(this);
        titleTv.setText("收银台");
        if (getIntent() != null) {
            moneyPay = ((PayInfo) getIntent().getSerializableExtra("payMoney"));
            switch (moneyPay.getIsUploadCheckMenu()) {
                case 0:
                    payMoney.setText("实际价格:￥" + moneyPay.getFinalPrice());
                    break;
                case 1:
                    payMoney.setText("实际价格:￥" + moneyPay.getTotalPrice() + "-26=" + moneyPay.getFinalPrice());
                    break;
            }
        }
    }

    @OnClick({R.id.wxRv, R.id.aliPayRv, R.id.payBuy, R.id.ly_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ly_back:
                finish();
                break;
            case R.id.wxRv:
                payType = 1;
                wxSelect.setImageResource(R.mipmap.icon_xz2);
                aliPaySelect.setImageResource(R.mipmap.icon_xz_copy);
                break;
            case R.id.aliPayRv:
                payType = 2;
                wxSelect.setImageResource(R.mipmap.icon_xz_copy);
                aliPaySelect.setImageResource(R.mipmap.icon_xz2);
                break;
            case R.id.payBuy:
                switch (payType) {
                    case 1:
                        EventBus.getDefault().post(new BussEvent(BussEvent.Order_Refush));
                        finish();
                        PayAgentUtils.getInstance().pay(this, PayAgent.PayType.WECHATPAY, moneyPay, new PayListener() {
                            @Override
                            public void onPaySuccess(PayAgent.PayType payType) {

                            }

                            @Override
                            public void onPayFail(PayAgent.PayType payType, int code, String msg) {
                            }
                        });
                        break;
                    case 2:
                        PayAgentUtils.getInstance().pay(this, PayAgent.PayType.ALIPAY, moneyPay, new PayListener() {
                            @Override
                            public void onPaySuccess(PayAgent.PayType payType) {
                                EventBus.getDefault().post(new BussEvent(BussEvent.Order_Refush));
                                finish();
                            }

                            @Override
                            public void onPayFail(PayAgent.PayType payType, int code, String msg) {
                            }
                        });
                        break;
                    default:
                        ToastUtil.shortShowToast("请先选择支付类型...");
                        break;
                }
                break;
        }
    }

}
